package com.wnxy;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
/**
 * 对象引用
 * VM Args: -Xms10m -Xmx10m 堆内存
 */
public class App7 {
    // 定义List集合
    private static List<Object> list = new ArrayList<Object>();

    public static void main(String[] args) {
        // 循环创建弱引用对象
        for (int i = 0; i < 10; i++) {
            byte[] buff = new byte[1024 * 1024];
            WeakReference<byte[]> sr = new WeakReference<byte[]>(buff);
            list.add(sr);
        }

        System.gc(); // 主动通知垃圾回收

        for (int i = 0; i < list.size(); i++) {
            Object obj = ((WeakReference) list.get(i)).get();
            System.out.println(obj);
        }
    }
}